﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECommerce.BLL.Advertisement;
using Jzy.Core.Utility;
using Jzy.Core.Common.Basic;
using Jzy.Core.Common.Web;
using ECommerce.Model.Advertisement;

namespace ECommerce.Web.ECAdmin.Advertisement
{
    public partial class List : PageList
    {
        private AdvertisementBO Ad
        {
            get
            {
                return AdvertisementBO.Instance<AdvertisementBO>();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindView();
            }
            base.InitSelectID(hidSelectIDs);
            AddAttr();
        }

        private void AddAttr()
        {
            JSUtil.ShowForm(lnkAdd, "增加广告", null, GlobalVar.WebCurrPath + "Edit.aspx", 400, 255);
            JSUtil.ClickBtn(lnkDelete, btnDelete);
            
        }
        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            BindView();
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (strSelectIDs != "")
            {
                this.Ad.Delete(StrUtil.SplitToStr(strSelectIDs));
            }
            BindView();
        }

        protected void lv_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                LVUtil.SetEdit(sender, e, 400, 255);

            }
        }

        private void BindView()
        {
            LVUtil.Init(lv, lvHeader);
            List<AdvertisementInfo> list = this.Ad.GetList();
            lv.DataKeyNames = new string[] { "ID" };
            lv.DataSource = list;
            lv.DataBind();
        }
    }
}